package com.tjsinfo.tjsoa.vote.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.vote.dao.ITVoteOpinionBoxDAO;
import com.tjsinfo.tjsoa.vote.vo.TVoteOpinionBox;

public class TVoteOpinionBoxBO implements ITVoteOpinionBoxBO {
	
	private IQbcDao qbcDao;	
	private ITVoteOpinionBoxDAO opinionBoxDao;

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}

	public void setOpinionBoxDao(ITVoteOpinionBoxDAO opinionBoxDao) {
		this.opinionBoxDao = opinionBoxDao;
	}

	public void delete(String id) {
		// TODO Auto-generated method stub
		opinionBoxDao.delete(id);
	}

	public TVoteOpinionBox findById(String id) {
		// TODO Auto-generated method stub
		return opinionBoxDao.findById(id);
	}

	public void save(TVoteOpinionBox transientInstance) {
		// TODO Auto-generated method stub
		opinionBoxDao.save(transientInstance);
	}


	public List<TVoteOpinionBox> selectAll(Integer first, Integer max,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TVoteOpinionBox.class);
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}	
	
	public List<TVoteOpinionBox> selectSelf(Integer first, Integer max,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TVoteOpinionBox.class);
		detachedCriteria.add(Restrictions.eq("userId", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("dateTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}

	public Integer selectTotal() {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TVoteOpinionBox.class);
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}	
	
	public void update(TVoteOpinionBox transientInstance) {
		// TODO Auto-generated method stub
		opinionBoxDao.update(transientInstance);
	}	
}
